<!DOCTYPE html>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport"
	content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<link rel="stylesheet" href="css/reset.css" />
<link rel="stylesheet" href="css/pullToRefresh.css" />
<link rel="stylesheet" href="css/style.service.css" />
<script type="text/javascript" src="js/jquery 2.1.1 min.js"></script>
<script src="js/iscroll.js"></script>
<script src="js/pullToRefresh.js"></script>

<!-- <style>
.tel{margin-top:10px}
.sale-addr{margin-bottom:10px}
</style> -->
</head>
<body>
	<!--must content ul li,or shoupi-->
	<div id="wrapper">
		<ul class="sale">
		</ul>
	</div>

	<script>
	
		function getQueryString(name) {
		   var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)","i");
		   var r = window.location.search.substr(1).match(reg);
		   if (r!=null) return (r[2]); return null;
		}
		var pageNo = getQueryString("pageNo")==null?0:getQueryString("pageNo")-1;
		var serviceType = getQueryString("serviceType")==null?1:getQueryString("serviceType");
		var longitude = getQueryString("longitude");
		var latitude = getQueryString("latitude");
		var haveData = true;
		
		
		
		
		refresher.init({
			id : "wrapper",
			pullDownAction : Refresh,
			pullUpAction : Load
		});
		var a = 1;
		var wh=$(window).height();
		$("#wrapper").height(wh);
		function Refresh() {
			
			haveData = true;
			pageNo = 1;
			$("#wrapper ul").children().remove();
			var serviceStation = loadData();
			var el, li;
			el = document.querySelector("#wrapper ul");
			$.each(serviceStation,function(index,data){
				if(serviceStation!=null && serviceStation.length>0){
					var type=data.service_type;
					li = document.createElement('li');
					var	html; 
					var str;
						//if(type==2){
							/* html="<ul>"+
							"	<li class='sale-addr'>"+data.service_station_name+"</li>";
							 str="<li style='display:none;' ><img src='img/map.png' />"+data.outlets_addr+"</li>"+
								"	<li class='tel'><p> <a href='tel:"+data.contact_phone+"'>"+data.contact_phone+"</a>" +
								"<img src='img/tel.png' /></p></li>"+
								"</ul>"; */
							/* html=" <div data-role= 'main ' class= 'ui-content '>"+
							"   <ul class= 'save '>    <li></li>                    "+
							"   	<li>                                     "+
							"   		<img src= 'img/taipingyang.png ' />    "+
							"   		<ul>                                   "+
							"   			<li>平安车险</li>    <li></li>                  "+
							"   			<li class='tel'>电话：<a href=\"tel:95511\">95511</a></li>                 "+
							"   		</ul>                                  "+
							"   	</li>                                    "+
							"   	<li>                                     "+
							"   		<img src= 'img/pingan.png ' />         "+
							"   		<ul>                                   "+
							"   			<li>太平洋车险</li>                  "+
							"   			<li  class='tel'>电话：<a href='tel:4006095500'>400-609-5500</a></li>          "+
							"   		</ul>                                  "+
							"   	</li>                                    "+
							"   	<li>                                     "+
							"   		<img src= 'img/BYD.png ' />            "+
							"   		<ul>                                   "+
							"   			<li>比亚迪</li>                      "+
							"   			<li  class='tel'>电话：<a href='tel:4008303666'>400-830-3666</a></li>          "+
							"   		</ul>                                  "+
							"   	</li>                                    "+
							"   	<li>                                     "+
							"   		<img src= 'img/BAIC-BJEV.png ' />      "+
							"   		<ul>                                   "+
							"   			<li>北汽新能源</li>                  "+
							"   			<li  class='tel' >电话：<a href='tel:4006506766'>400-650-6766</a></li>          "+
							"   		</ul>                                  "+
							"   	</li>                                    "+
							"   		<li>                                   "+
							"   		<img src= 'img/tesla.png ' />          "+
							"   		<ul>                                   "+
							"   			<li>特斯拉</li>                      "+
							"   			<li  class='tel' >电话：<a href='tel:4009100707'>400-910-0707</a></li>          "+
							"   		</ul>                                  "+
							"   	</li>                                    "+
							"   		<li>                                   "+
							"   		<img src= 'img/yangguanchexian.png ' />"+
							"   		<ul>                                   "+
							"   			<li>阳光车险</li>                    "+
							"   			<li  class='tel'>电话：<a href='tel:95510'>95510</a></li>                 "+
							"   		</ul>                                  "+
							"   	</li>   <li></li>                                  "+
							"   </ul>                                      "+
							" </div>                                       "	;
							str=""; */
							//li.innerHTML=html+str;
							//el.appendChild(li, el.childNodes[0]);
							//break;
						//}else{
							html="<ul  onclick='detail(\""+data.service_station_id+"\");' >"+
							"	<li class='sale-addr'>"+data.service_station_name+"</li>";
						 str=	"	<li class='sale-detail_addr'><img src='img/map.png' />"+data.outlets_addr+"</li>"+
							"	<li style='display:none;'><img src='img/map.png' />"+data.contact_phone+"</li>"+
							"	<li><span>"+data.dis+" km</span></li>"+
							"</ul>";
						//}
						 li.innerHTML=html+str;
							el.appendChild(li, el.childNodes[0]);
							/* if(type==2){
								 return false;
							 } */
				}
			});
			wrapper.refresh();
			document.getElementById("wrapper").querySelector(".pullDownLabel").innerHTML = "刷新成功";
		}

		function Load() {
			
			if(haveData){
				pageNo++;
			}
			var serviceStation = loadData();
			if(serviceStation!=null && serviceStation.length>0){
				var el, li;
				el = document.querySelector("#wrapper ul");
				$.each(serviceStation,function(index,data){
						var type=data.service_type;
						li = document.createElement('li');
						var html;
						var str;
						//if(type==2){
							/* html="<ul>"+
							"	<li class='sale-addr'>"+data.service_station_name+"</li>";
							 str="<li style='display:none;' ><img src='img/map.png' />"+data.outlets_addr+"</li>"+
							 "	<li class='tel'><p> <a href='tel:"+data.contact_phone+"'>"+data.contact_phone+"</a>" +
								"<img src='img/tel.png' /></p></li>"+
								"</ul>"; */
							/* html=" <div data-role= 'main ' class= 'ui-content '>"+
							"   <ul class= 'save '>     <li></li>                   "+
							"   	<li>                                     "+
							"   		<img src= 'img/taipingyang.png ' />    "+
							"   		<ul>                                   "+
							"   			<li>平安车险</li>    <li></li>                 "+
							"   			<li class='tel' >电话：<a href=\"tel:95511\">95511</a></li>                 "+
							"   		</ul>                                  "+
							"   	</li>                                    "+
							"   	<li>                                     "+
							"   		<img src= 'img/pingan.png ' />         "+
							"   		<ul>                                   "+
							"   			<li>太平洋车险</li>                  "+
							"   			<li  class='tel'>电话：<a href='tel:4006095500'>400-609-5500</a></li>          "+
							"   		</ul>                                  "+
							"   	</li>                                    "+
							"   	<li>                                     "+
							"   		<img src= 'img/BYD.png ' />            "+
							"   		<ul>                                   "+
							"   			<li>比亚迪</li>                      "+
							"   			<li  class='tel'>电话：<a href='tel:4008303666'>400-830-3666</a></li>          "+
							"   		</ul>                                  "+
							"   	</li>                                    "+
							"   	<li>                                     "+
							"   		<img src= 'img/BAIC-BJEV.png ' />      "+
							"   		<ul>                                   "+
							"   			<li>北汽新能源</li>                  "+
							"   			<li  class='tel'>电话：<a href='tel:4006506766'>400-650-6766</a></li>          "+
							"   		</ul>                                  "+
							"   	</li>                                    "+
							"   		<li>                                   "+
							"   		<img src= 'img/tesla.png ' />          "+
							"   		<ul>                                   "+
							"   			<li>特斯拉</li>                      "+
							"   			<li  class='tel'>电话：<a href='tel:4009100707'>400-910-0707</a></li>          "+
							"   		</ul>                                  "+
							"   	</li>                                    "+
							"   		<li>                                   "+
							"   		<img src= 'img/yangguanchexian.png ' />"+
							"   		<ul>                                   "+
							"   			<li>阳光车险</li>                    "+
							"   			<li  class='tel'>电话：<a href='tel:95510'>95510</a></li>                 "+
							"   		</ul>                                  "+
							"   	</li>    <li></li>                                "+
							"   </ul>                                      "+
							" </div>                                       ";
							str="";
							//li.innerHTML=html+str;
							//el.appendChild(li, el.childNodes[0]);
								//break;
						}else{ */
							html= 
								"<ul  onclick='detail(\""+data.service_station_id+"\");' >"+
								"	<li class='sale-addr'>"+data.service_station_name+"</li>";
						 str=	"	<li class='sale-detail_addr'><img src='img/map.png' />"+data.outlets_addr+"</li>"+
							"	<li style='display:none;'><img src='img/map.png' />"+data.contact_phone+"</li>"+
							"	<li><span>"+data.dis+" km</span></li>"+
							"</ul>";
						//}
						 li.innerHTML=html+str;
						 el.appendChild(li, el.childNodes[0]);	
						 /* if(type==2){
							 return false;
						 } */
					
				});
				wrapper.refresh();
			}
			else{
				haveData = false;
				wrapper.refresh();
				document.getElementById("wrapper").querySelector(".pullUpLabel").innerHTML = "没有更多数据";						
			}
		}
		function loadData(){
			var res = new Object();
			$.ajax({
				url : "/appserver/pub/serviceStation",
				type : "GET",
				async : false,
				data : {
					'serviceType' : serviceType,
					'longitude' : longitude,
					'latitude' : latitude,
					'pageNo' : pageNo
				},
				dataType : "json",
				success : function(resData) {

					if(resData.code!="200"){
						alert("网络异常");
						wrapper.refresh();
						return;
					}
					res = resData;
				},
				fail : function() {
					alert("网络异常");
				}
			});
			return res.data;
		}
		Load();
		
		function detail(serviceStationId){
			window.location.href="salePoints.html?serviceStationId="+serviceStationId;
		}
	</script>
</body>
</html>










